Skip to content

grpc ensure FIFO order of jobs stored by the server - #2209

Merged
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
tmckayus:fix/grpc-queue-fairness
Oct 26, 2026
Merged

rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
tmckayus:fix/grpc-queue-fairness

Conversation

@tmckayus

Copy link
Copy Markdown
Contributor

The grpc server algorithm to read the job data structure could result in client starvation if multiple clients submitted to the server at the same time, and the clients submitting the first jobs to run continuously submitted new jobs whenever it's current job completed.

Add a monotonically increasing ticket number associated with jobs to ensure that workers solve jobs in FIFO order. Workers now scan the job structure to find the lowest ticket number and run that job.

This was tested and verified on a harness that identified the original problem: run 100 clients in separate processes for 5 minutes and check the job completion total of each client. Without the fix, most gRPC clients would starve under this scenario. With this fix, none starve and over roughly 30,000 jobs the totals are roughly equal.

use a monotonically increasing ticket number associated with
jobs to ensure that workers solve jobs in FIFO order
@tmckayus
tmckayus requested a review from a team as a code owner October 24, 2026 22:38
@tmckayus tmckayus added bug Something isn't working non-breaking Introduces a non-breaking change labels Oct 24, 2026
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cuopt
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: f4ba3a8
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: ed6592a7-ee93-4308-86d5-e8d4ec0cf329
Commits

Reviewing files that changed from the base of the PR and between 512e030 and 24e2898.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cuopt
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: b5ad4d0
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 3225a594-3c97-4924-b819-b2fdd74eaf80
Commits

Reviewing files that changed from the base of the PR and between 5803e45 and 512e030.

Files selected for processing: 6
  • cpp/src/grpc/server/grpc_job_queue.hpp
  • cpp/src/grpc/server/grpc_server_main.cpp
  • cpp/src/grpc/server/grpc_worker.cpp
  • cpp/src/grpc/server/grpc_worker_infra.cpp
  • cpp/tests/linear_programming/grpc/CMakeLists.txt
  • cpp/tests/linear_programming/grpc/grpc_job_queue_test.cpp
Files with no reviewable changes: 2
  • cpp/src/grpc/server/grpc_server_main.cpp
  • cpp/src/grpc/server/grpc_worker.cpp

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

Walkthrough

The gRPC job queue now assigns an enqueue sequence when a job slot becomes ready. Workers claim ready, unclaimed slots in sequence order. Shared reset logic clears slot state, and tests cover ordering, claiming, reset, and concurrent worker claims.

Changes: gRPC job queue ordering

Layer / File(s) Summary
Queue state and sequence contract
cpp/src/grpc/server/grpc_job_queue.hpp, cpp/src/grpc/server/grpc_server_types.hpp, cpp/src/grpc/server/grpc_server_main.cpp
The shared-memory slot definition includes enqueue sequence state. Server state initializes the next sequence to 1, and queue initialization sets each slot sequence to 0.
Publish and claim jobs
cpp/src/grpc/server/grpc_job_management.cpp, cpp/src/grpc/server/grpc_job_queue.hpp, cpp/src/grpc/server/grpc_worker.cpp, cpp/tests/linear_programming/grpc/*
Both asynchronous submission paths publish through a helper that assigns a sequence and sets the slot ready. Workers claim the eligible slot with the lowest nonzero sequence. Submission logs include the assigned sequence. Tests cover ordered claims, worker assignment, and concurrent claims.
Reset and release slot state
cpp/src/grpc/server/grpc_job_queue.hpp, cpp/src/grpc/server/grpc_worker.cpp, cpp/src/grpc/server/grpc_worker_infra.cpp, cpp/tests/linear_programming/grpc/grpc_job_queue_test.cpp
Slot reset clears readiness before resetting the enqueue sequence and remaining slot metadata. Failed-worker cleanup uses the shared reset helper. Tests check reset behavior.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • Issue 2210 describes slot scanning that can select jobs out of arrival order and starve waiting jobs. This PR assigns sequences and claims the lowest-sequence ready job.
Merge Risk: Minimal · up to 512e0

The queue changes are ready to merge after normal checks; no concrete ordering or slot-reuse issue remains identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 7 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "grpc ensure FIFO order of jobs stored by the server" matches the main change. The PR adds a monotonically increasing enqueue sequence (ticket number) to job slots, and workers claim the rea…
Description check Passed The description explains the problem (client starvation when early clients keep resubmitting), the fix (monotonic ticket numbers, workers select the lowest ticket), and the testing harness with 100 cl…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "grpc ensure FIFO order of jobs stored by the server" matches the main change. The PR adds a monotonically increasing enqueue sequence (ticket number) to job slots, and workers claim the ready job with the lowest sequence, which gives FIFO ordering. The title is specific and short, and it names the affected area (grpc server).

Full details: Description check

Explanation

The description explains the problem (client starvation when early clients keep resubmitting), the fix (monotonic ticket numbers, workers select the lowest ticket), and the testing harness with 100 clients and roughly 30,000 jobs. These points match the raw summary, which covers the enqueue sequence, the claim logic in grpc_job_queue.hpp, and the new concurrent test.

Full details: Docstring Coverage

Explanation

Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 7 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@tmckayus

Copy link
Copy Markdown
Contributor Author

/ok to test 5803e45

@ramakrishnap-nv
ramakrishnap-nv requested a review from a team as a code owner October 26, 2026 14:49
@github-actions

Copy link
Copy Markdown

CI Test Summary

1 failed · 20 passed · 0 skipped

  • wheel-tests-cuopt-server / 13.3.0, 3.14, amd64, ubuntu24.04, h100, latest-driver, latest-deps — failed; no test names found in log (job log)

@ramakrishnap-nv

Copy link
Copy Markdown
Collaborator

/merge

@rapids-bot
rapids-bot Bot merged commit 476a0c4 into NVIDIA:main Oct 26, 2026
161 of 165 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants